package spring.boot.adminx.controller;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.security.core.context.SecurityContextHolder;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.GetMapping;
import spring.boot.adminx.model.SysMenu;
import spring.boot.adminx.model.SysUser;
import spring.boot.adminx.service.SysMenuService;

import java.util.List;

@Controller
public class HomeController {

    @Autowired
    private SysMenuService sysMenuService;


    @GetMapping("/home")
    @PreAuthorize("true")
    public String home(Model model){
        SysUser sysUser = (SysUser) SecurityContextHolder.getContext().getAuthentication().getPrincipal();
        List<SysMenu> menus = sysMenuService.selectLeftMenu(sysUser.getId());
        model.addAttribute("leftList",menus);
        return "home";
    }

    @GetMapping("/error")
    @PreAuthorize("true")
    public String error(){
        return "error";
    }

    @GetMapping("/limit")
    @PreAuthorize("true")
    public String limit(){
        return "error";
    }
}

